package com.aopcinemas.cinema;

import jade.domain.DFService;
import jade.domain.FIPAException;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.domain.FIPAAgentManagement.ServiceDescription;

import com.aopcinemas.cinema.model.Cinema;

public class CinemaUtils {

    public static void registerCinema(CinemaAgent agent, Cinema cinema) {
        DFAgentDescription dfd = new DFAgentDescription();
        dfd.setName(agent.getAID());
        ServiceDescription sd = new ServiceDescription();
        sd.setType(CinemaConstants.CINEMA_SERVICE_TYPE);
        sd.setName(cinema.getOrganization());
        dfd.addServices(sd);

        try {
            DFService.register(agent, dfd);
        } catch (FIPAException e) {
            throw new RuntimeException("Can't register cinema!");
        }

        agent.setCinema(cinema);
    }

    public static void unregisterCinema(CinemaAgent agent) {
        try {
            DFService.deregister(agent);
        } catch (FIPAException e) {
            throw new RuntimeException("Can't register cinema!");
        }
        agent.setCinema(null);
    }

}
